package com.iot.inclinometer.util;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.iot.inclinometer.R;

import java.util.List;
import java.util.Map;

public class TableAdapter extends BaseAdapter {
	private Context context = null;
	private List<Map<String, Object>> listItems = null;
	private TextView depth;
	private TextView offset;
	private int currentRow;
	public TableAdapter(){}
	
	public TableAdapter(List<Map<String, Object>> data, Context context,int row) {
		this.context = context;
		listItems = data;
		currentRow = row;
	}

	@Override
	public int getCount() {
		return listItems.size();
	}

	@Override
	public Object getItem(int position) {
		return listItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		Map<String, Object> item = listItems.get(position);

		view=LayoutInflater.from(context).inflate(R.layout.item_table,null);
		
		
		depth = (TextView) view.findViewById(R.id.depth);
		offset = (TextView) view.findViewById(R.id.offset);
		
		depth.setText(item.get("depth").toString());
		offset.setText(item.get("error").toString());
		if(currentRow==position&&currentRow==0&&position==0){
			depth.setBackgroundColor(Color.YELLOW);
			offset.setBackgroundColor(Color.YELLOW);
		}else{
			if(currentRow==position&&position!=0){
				depth.setBackgroundColor(Color.YELLOW);
				offset.setBackgroundColor(Color.YELLOW);
			}
		}
		view.setTag(position);
		return view;
	}

}
